﻿// -----------------------------------------------------------------------
// <copyright file="ServiceInformation.cs" company="None">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace ODataTestFrameworkCore.shared
{
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;

    enum EntityFilterCondition
    {
        Include,
        Exclude
    }
    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class ODataServiceInformation
    {
        public string ServiceURI;
        public string ServiceBusinessName;
        // public string EnviromentTag;// DEV, QA , ETC 

        string EntityFilerString;
        EntityFilterCondition EntityFilerType;

        public ODataServiceInformation(string serviceBusinessName, string entityFilerString, string serviceURI)
        {
            this.ServiceBusinessName = serviceBusinessName;
            this.ServiceURI = serviceURI;
            this.EntityFilerString = entityFilerString;//Default 
            EntityFilerType = EntityFilterCondition.Include;  //Default 

            if (this.EntityFilerString.Contains("="))
            {
                string[] splitFilter = this.EntityFilerString.Split('=');
                string condition = splitFilter[0];
                this.EntityFilerString = splitFilter[1];
                if (condition == "!")
                {
                    EntityFilerType = EntityFilterCondition.Exclude;
                }
                else
                {
                    throw new ApplicationException(string.Format("Unsupported Entity Filter in config file Supplied={0}  ,Expecting={1}", condition, "!"));
                }
            }

        }

        public bool IncludeEntityCollectionInTest(string enitityCollectionName)
        {
            bool result=true;
            if (!(string.IsNullOrEmpty(this.EntityFilerString)||this.EntityFilerString=="*"))
            {
                if (EntityFilerType == EntityFilterCondition.Include)
                {
                    result = this.EntityFilerString.Contains(enitityCollectionName);
                }
                else
                {
                    result = !this.EntityFilerString.Contains(enitityCollectionName);
                }
            }
           


            return result;
        }
    }
}
